$(document).ready( function() {
    $('input[name=username]').focus();

    var errorContainer = $( "#error_container" );
    
    var adminLoginFormValidator = $('#login_form').validate({
        submitHandler: function(form) {
            form.submit();
        },
        errorElement: "div",
        errorClass: "incorrect_field",
        errorPlacement: function(error, element) { 
            // remove existing error label first
            //element.parents(".input_text_field").next(".error_field").find(".incorrect_field").remove();
            errorContainer.html( "" );
            error.appendTo( errorContainer );
        },
        rules: {
            username: {
                required: true
            },
            password: {
                required: true,
                minlength: 4
            }
        },
    
        messages: {
            username: "<div class='error'><div class='error_text'>" + Messages.Admin.Login + "</div></div>",
            password: "<div class='error'><div class='error_text'>" + Messages.Admin.Password + "</div></div>"
        }
    });
    
    $("#btnLogin").click( function(){
        $("#login_form").submit();
    });
    
    if ( $( "#logging_error" ).val() != "" )
    {
        adminLoginFormValidator.showErrors( {'username': "<div class='error'><div class='error_text'>" + Messages.Admin.Login + "</div></div>"} );
    }
});